<?php
class Shop_Form_Category_Add extends Promotor_Form_Scaffold {
	public function init() {
		$this->setMethod('post');
		$this->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);

		$this->addPrefixPath('Promotor_Form_Decorator_','Promotor/Form/Decorator', self::DECORATOR);
        
		$subForm = $this->_getContentForm();
        $this->addSubForm($subForm, 'contenttab');
        
        $subForm = $this->_getDescriptionForm();
        $this->addSubForm($subForm, 'descriptiontab');
        
        $subForm = $this->_getSeoForm();
        $this->addSubForm($subForm, 'seotab');
        
        $subForm = $this->_getExForm();
        $this->addSubForm($subForm, 'exttab');
	}
	

	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getContentForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'contenttab',
            'legend' => 'Kategoria',
        ));
        $subForm
        	->addElement(
                'text',
                'name',
                array(
                    'label' => 'Nazwa kategorii',
                    'required'  => true,
                )
            )
            ->addElement(new KontorX_Form_Element_File('image', array(
        		'label' => 'Zdięcie/Logo',
        		'required' => false,
        		'destination' => Shop_Model_Category::UPLOAD_PATH,
        		'filters' => array(
        			'UniqName' => new KontorX_Filter_File_UniqName()
        		),
        		'validators' => array(
        			'upload' => array(
        				'validator' => 'Upload'),
        			'isImage' => array(
        				'validator' => 'IsImage'),
        			'size' => array(
        				'validator' => 'Size',
        				'options' => array(
        					'min' => '3kb',
        					'bytestring' => true)),
        			'count' => array(
        				'validator' => 'Count',
        				'options' => array(
        					'max' => 1))
        		)
        	)));

        return $subForm;
    }
    
	/**
     * @return Zend_Form_SubForm
     */
    protected function _getDescriptionForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'descriptiontab',
            'legend' => 'Opis',
        ));

		$content = new Zend_Form_Element_Textarea('description', array(
			'label'        => 'Opis produktu',
			'inheritWidth' => 'true',
            'required' 	   => false
		));
		$content->addDecorator(new KontorX_Form_Decorator_TinyMCE());
		$subForm->addElement($content);

        return $subForm;
    }

    /**
     * @return Zend_Form_SubForm
     */
    protected function _getSeoForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'metatab',
            'legend' => 'Pozycjonowanie'
        ));
        $subForm
        	->addElement(
                'text',
                'alias',
                array(
                    'label' => 'Alias produktu',
                    'required'  => true,
                    'regExp' => '[\wds\-]+',
                    'invalidMessage' => 'Tylko tekst bez polskich znaków diakrytycznych!',
                	'filters' => array(
                		'strtrim' => new Zend_Filter_StringTrim(),
                		'strtolower' => new Zend_Filter_StringToLower(),
                		'rewrite' => new KontorX_Filter_Word_Rewrite()
                	),
                	'validators' => array(
                		'db_no_exsists' => new Zend_Validate_Db_NoRecordExists(
                				'shop_product','alias', array(
                					'field' => 'id',
                					'value' => current($this->getPrimaryKey())))
                	)
                )
            )
            ->addElement(
                'Textarea',
                'meta_keywords',
                array(
                    'label'      => 'Słowa kluczowe',
                    'trim'       => true,
                	'validators' => array(
                		'strlen' => new Zend_Validate_StringLength(10, 90)
                	)
				)
            )
            ->addElement(
                'Textarea',
                'meta_description',
                array(
                    'label'      => 'Opis strony',
                    'trim'       => true,
                	'validators' => array(
                		'strlen' => new Zend_Validate_StringLength(10, 90)
                	)
                )
            );
            
        return $subForm;
    }
    
	/**
     * @return Zend_Form_SubForm
     */
    protected function _getExForm() {
    	$subForm = new Zend_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'exttab',
            'legend' => 'Zaawansowane'
        ));
        $subForm
            ->addElement(
            	'checkbox',
            	'publicated',
            	array(
            		'label' => 'Publikować',
            		'checked' => true
            	)
            );
            
        return $subForm;
    }
}